package com.lianniu.mgr.baseService.post.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.area.model.SystemAreaVo;
import com.lianniu.mgr.baseService.post.dao.IAssignAuthorityMapperDao;
import com.lianniu.mgr.baseService.post.dao.ICheckAuthorityMapperDao;
import com.lianniu.mgr.baseService.post.model.Sys2Menu2OpVo;
import com.lianniu.mgr.baseService.post.service.ICheckAuthorityService;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.util.StringUtil;
import org.springframework.stereotype.Service;

@Service
public class CheckAuthorityServiceImpl implements ICheckAuthorityService {

  private final static Logger logger = Logger.getLogger(CheckAuthorityServiceImpl.class);
  @Resource
  private ICheckAuthorityMapperDao checkAuthorityMapperDao;
  
  @Resource
  private IAssignAuthorityMapperDao assignAuthorityMapperDao;
  
  /**
   * @Description:查询有权限的区域
   * @param postId
   * @return BaseResult(data=List<SystemAreaVo>)

   * @Date:2016年3月29日下午8:42:36
   * @Version 1.1.0
   */
  @Override
  public BaseResult getPrecinctAuthorityByPostId(String postId) {
    logger.info("CheckAuthorityServiceImpl getPrecinctAuthorityByPostId begin.");
    logger.info("postId:" + postId);
    
    logger.info("input data check begin.");
    if(StringUtil.isEmpty(postId)){
      return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
    }
    logger.info("input data check end.");

    logger.info("getAreaByPostId begin.");
    List<SystemAreaVo> list=checkAuthorityMapperDao.getAreaByPostId(postId);
    logger.info("getAreaByPostId end.");
    logger.info("CheckAuthorityServiceImpl getPrecinctAuthorityByPostId end.");
    return BaseResult.success(list);
  }
  
  /**
   * @Description:根据postId查询菜单操作
   * @param postId
   * @return BaseResult

   * @Date:2016年4月8日上午10:53:58
   * @Version 1.0.0
   */
  @Override
  public BaseResult getOpMenuByPostId(String postId){
    logger.info("CheckAuthorityServiceImpl getOpMenuByPostId begin.");
    logger.info("postId:" + postId);
    
    logger.info("input data check begin.");
    if(StringUtil.isEmpty(postId)){
      return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
    }
    logger.info("input data check end.");
    
    logger.info("getOpMenuByPostId begin.");
    List<Sys2Menu2OpVo> list=assignAuthorityMapperDao.getOpMenuByPostId(postId);
    logger.info("getOpMenuByPostId end.");
    
    logger.info("CheckAuthorityServiceImpl getOpMenuByPostId end.");
    return BaseResult.success(list);
  }
}
